import cn.golxen.rsms.RsmsApplication;
import cn.golxen.rsms.bean.bo.WeChatPayV2Bo;
import cn.golxen.rsms.commons.utils.LocalDateTimeUtils;
import cn.golxen.rsms.commons.utils.MailUtils;
import cn.golxen.rsms.commons.utils.YmlUtils;
import cn.golxen.rsms.redis.PayRedis;
import cn.golxen.rsms.redis.RedisUtils;
import cn.golxen.rsms.service.BusinessService;
import cn.golxen.rsms.service.StoreService;
import cn.golxen.rsms.service.WxService;
import com.alibaba.excel.util.BeanMapUtils;
import com.alibaba.fastjson.JSONObject;
import com.github.wxpay.sdk.WXPayConstants;
import com.github.wxpay.sdk.WXPayUtil;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.stereotype.Component;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.web.client.RestTemplate;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.time.temporal.Temporal;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Slf4j
@RunWith(SpringRunner.class)
@SpringBootTest(classes = RsmsApplication.class)
public class test {
    @Autowired
    BusinessService businessService;
    @Autowired
    StoreService storeService;
    @Autowired
    WxService wxService;

    @Test
    public void testTimerSuggestedPrice() {
        new RedisUtils().timerSuggestedPrice("1111");
    }

    @Test
    public void testBeanToMap() {
        WeChatPayV2Bo weChatPayV2Bo = new WeChatPayV2Bo();
        weChatPayV2Bo.setAuth_code("1111111111");
        weChatPayV2Bo.setAppid(YmlUtils.getString("wechat.appid"));
        weChatPayV2Bo.setMch_id("1636971735");
        weChatPayV2Bo.setNonce_str(String.valueOf(System.currentTimeMillis()));
        weChatPayV2Bo.setBody("rsms收银-微信支付款码支付");
        weChatPayV2Bo.setAttach("1111111111");
        weChatPayV2Bo.setApi_key(YmlUtils.getString("wechat.apiV2-key"));
        String outTradeNo = "1111111111";
        weChatPayV2Bo.setOut_trade_no(outTradeNo);
        double totalD = 100.00 * 100;
        Integer totalI = (int) totalD;
        weChatPayV2Bo.setTotal_fee(String.valueOf(totalI));
        Map<String, String> map = new HashMap<>();
        map = BeanMapUtils.create(weChatPayV2Bo);
        try {
            map.put("sign", WXPayUtil.generateSignature(map, weChatPayV2Bo.getApi_key(), WXPayConstants.SignType.MD5));
        } catch (Exception e) {
            e.printStackTrace();
        }
        log.info("111111111111111111111" + map);
        try {
            String xmlBody = WXPayUtil.generateSignedXml(map, weChatPayV2Bo.getApi_key());
            log.info("placeOrderByAuthCode信息----XML：" + xmlBody);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Test
    public void test1() throws ParseException {
        String startDate="2023-03-08 00:00:00";
        String endDate="2023-03-09 00:00:00";

        Date localDateTime1=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(startDate);
        Date localDateTime2=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(endDate);
        log.info(String.valueOf(localDateTime2.equals(localDateTime2)));

    }

    @Test
    public void test2() {
        wxService.sendBusiness();
//        RestTemplate restTemplate=new RestTemplate();
//        restTemplate.postForObject("http://wx.golxen.com/WxServlet", "[\n" +
//                "     {\n" +
//                "          \"date\": \"2023-03-24T00:00:00\",\n" +
//                "          \"newCustomerNum\": 0,\n" +
//                "          \"oldCustomerNum\": 1,\n" +
//                "          \"salesVolume\": 0.1,\n" +
//                "          \"storeId\": 1636971735,\n" +
//                "          \"storeName\": \"诚心惠\",\n" +
//                "          \"transactionsNum\": 1,\n" +
//                "          \"openId\":\"oej9T6Bhr-35F3r2ksAtFKgfIjVk\"\n"+
//                "     }\n" +
//                "]",String.class);
//        storeService.sendMail();
    }
}